#include <iostream>
#include <pthread.h>
#include <unistd.h>
using namespace std;

int tickets = 1000;

void* Ticket(void *argv)
{
    while(1)
    {
        if(tickets>0)
        {
            usleep(1000);
            printf("[%p]:线程:%d号\n",pthread_self(),tickets--);
        }
        else
        {
            break;
        }   
    }
    return nullptr;
}

int main()
{
    pthread_t t1,t2,t3;

    pthread_create(&t1,nullptr,Ticket,(void*)nullptr);
    pthread_create(&t2,nullptr,Ticket,(void*)nullptr);
    pthread_create(&t3,nullptr,Ticket,(void*)nullptr);

    pthread_join(t1,nullptr);
    pthread_join(t2,nullptr);
    pthread_join(t3,nullptr);

    return 0;
}